package com.wc.service;

import com.wc.bean.Menu;
import com.wc.bean.Role;
import com.wc.bean.User;
import com.wc.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WcUserServicelmpl implements WcUserService {
 @Autowired
    UserMapper userMapper;
    public User queryUserByName(String user_name){
        User user = userMapper.queryUserByName(user_name);
        return user;
    }

    public int register(User user){
        User ruser = userMapper.queryUserByName(user.getUserName());
        if(ruser != null && ruser.getUserName().equals(user.getUserName())){
            return 1;
        }
        int r = userMapper.register(user);
        System.out.println(r+"插入数据");
        if(r == 1){
            return 0;
        }else{
            return 2;
        }
    }

    public List<User> login(Map<String,Object> map){
        List<User> users = userMapper.login(map);
        return users;
    }
    public List<Menu> selectRole(Role role){
        List<Menu> Menus = userMapper.selectRole(role);
        return Menus;
    }

    public Role selectRname(Map<String,Object> map) {
        Role Rname = userMapper.selectRname(map);
        return Rname;
    }
//    public int login(Map<String,Object> map){
//        if(userMapper.queryUserByName(){
//            int r = userMapper.login();
//            System.out.println(r+"插入数据");
//            if(r == 1){
//                return 0;
//            }else{
//                return 2;
//            }
//        }
//
//    }
}
